/**
 * Created by YJH on 2018/6/11.
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Image,
    DeviceEventEmitter,
} from 'react-native';
import Toast, {DURATION} from 'react-native-easy-toast';
import {ACTION_NOTIFY} from './HomePage';

export const FLAG_TAB = {
    flag_popularTab: 'tb_popular',
    flag_trendingTab: 'tb_trending',
    flag_favoriteTab: 'tb_favorite',
    flag_my: 'tb_my'
};
export default class BasePage extends Component<Props> {

    constructor(props) {
        super(props);
        this.state = {
            theme: this.props.theme,
        }
    }


    componentDidMount() {
        //组件加载完成之后，注册通之
        this.baseListener = DeviceEventEmitter.addListener('ACTION_BASE', (action, params) => {
            this.onBaseAction(action, params)
        })

    }

    onBaseAction(action, params) {
        if (action === ACTION_NOTIFY.changeTheme) {
            this.onChangeTheme(params);
        }
    }

    /**
     * 功能：通知页面更新主题
     * @param notifyTheme
     */
    onChangeTheme(notifyTheme) {
        if (!notifyTheme)return;
        this.props.theme=notifyTheme;
        this.setState({
            theme: notifyTheme,
        });
    }

    componentWillUnmount() {
        this.baseListener && this.baseListener.remove();
    }

}